package m.jclecai.com.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import m.jclecai.com.R;
import m.jclecai.com.adapter.base.ViewHolerAdapter;
import m.jclecai.com.adapter.holder.BankListHolder;
import m.jclecai.com.bean.BankBean;

/**
 * Created by ZD on 2017/6/8.
 */

public class BankListAdapter extends ViewHolerAdapter<BankListHolder> {
    Context mContent;
    List<BankBean> mList;
    String[] banks;
    boolean showCheck = false;



    public BankListAdapter(Context content, List<BankBean> list) {
        this.mContent = content;
        this.mList = list;
        banks = content.getResources().getStringArray(R.array.bank_name);
    }

    @Override
    public BankListHolder onCreateViewHolder(int position, ViewGroup parent) {
        return new BankListHolder(mContent, R.layout.item_bank_list);
    }

    @Override
    public void onBindViewHolder(int position, BankListHolder bankListHolder) {
        final BankBean bankBean = mList.get(position);
        bankListHolder.init(bankBean, banks, showCheck);
        //将事件暴露出去；
        bankListHolder.setOnClickDelListener(new BankListHolder.OnClickDelListener() {
            @Override
            public void onClickDel() {
                if (mOnItemListener != null) {
                    mOnItemListener.onClickDel(bankBean);
                }
            }

            @Override
            public void onClickSetDefault(View view, boolean isChecked) {
                if (mOnItemListener != null) {
                    mOnItemListener.onClickSetDefault(view,isChecked,bankBean);
                }
            }
        });
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    public void setShowCheck(boolean showCheck) {
        this.showCheck = showCheck;
        notifyDataSetChanged();
    }

    public interface  OnItemListener{
        void onClickDel(BankBean bankBean);
        void onClickSetDefault(View view, boolean isChecked, BankBean bankBean);
    }

    public OnItemListener mOnItemListener;

    public void setOnItemListener(OnItemListener onItemListener) {
        mOnItemListener = onItemListener;
    }
}
